-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Integer methods for Wrapping #48810
Implement Integer methods for Wrapping #48810
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @BurntSushi (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/libcore/num/wrapping.rs
Outdated
#[inline] | ||
#[unstable(feature = "wrapping_int_impl", issue = "32463")] | ||
pub fn pow(self, exp: u32) -> Self { | ||
Wrapping(self.0.pow(exp)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one should call wrapping_pow? And maybe include a doctest demonstrating that it wraps...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to name it pow
to mirror the names on u8
etc. These impls are intended to make generic code that operates on integer types work seamlessly with wrapping integer types, and that requires the method names to be the same.
I'll add a wrapping example to the doctest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @scottmcm meant that within, it should call self.0.wrapping_pow(exp)
. Otherwise, it might actually overflow / panic.
src/libcore/num/wrapping.rs
Outdated
@@ -355,3 +651,6 @@ mod shift_max { | |||
pub const u64: u32 = i64; | |||
pub use self::platform::usize; | |||
} | |||
|
|||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[00:06:04] tidy error: /checkout/src/libcore/num/wrapping.rs:528: trailing whitespace
[00:06:04] tidy error: /checkout/src/libcore/num/wrapping.rs: too many trailing newlines (4)
afb1870
to
02aa39f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@bors r+ |
📌 Commit 910d855 has been approved by |
…wrapping, r=dtolnay Implement Integer methods for Wrapping Wrapping<T> now implements: count_ones, count_zeros, leading_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be, from_le, to_be, to_le, and pow where T is: u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize. Docs were written for all these methods, as well as examples. The examples mirror the ones on u8, u16, etc... for consistency. Closes rust-lang#32463
@bors rollup |
…wrapping, r=dtolnay Implement Integer methods for Wrapping Wrapping<T> now implements: count_ones, count_zeros, leading_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be, from_le, to_be, to_le, and pow where T is: u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize. Docs were written for all these methods, as well as examples. The examples mirror the ones on u8, u16, etc... for consistency. Closes rust-lang#32463
@bors rollup- |
⌛ Testing commit 910d855 with merge 2b0dbffed5e11b4b565e4011d77ccf12493bd82b... |
💔 Test failed - status-travis |
Is there something wrong with my PR...? A rollup error log doesn't usually show up directly under a PR. The error is weird, though... something about duplicate rustdoc for |
@Phlosioneer It was removed from the rollup, see #48810 (comment) (I don't understand the error either.) |
uhm, what do I need to do? I don't think this is |
@Phlosioneer Try to change (cc @GuillaumeGomez about the order change on i686.) |
I’ve filed #49123 for that rustdoc test failure. |
Wrapping<T> now implements: count_ones, count_zeros, leading_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be, from_le, to_be, to_le, and pow where T is: u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize. Docs were written for all these methods, as well as examples. The examples mirror the ones on u8, u16, etc... for consistency. Closes rust-lang#32463
910d855
to
bf101a5
Compare
I rebased against master, and I don't see #49123 during local testing. We'll see if travis agrees. |
I have no idea why there is a change in the order... If there is a problem, I think it comes from the internals of rust instead of rustdoc. |
@bors r=dtolnay Let's try again then. |
📌 Commit bf101a5 has been approved by |
…wrapping, r=dtolnay Implement Integer methods for Wrapping Wrapping<T> now implements: count_ones, count_zeros, leading_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be, from_le, to_be, to_le, and pow where T is: u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize. Docs were written for all these methods, as well as examples. The examples mirror the ones on u8, u16, etc... for consistency. Closes rust-lang#32463
@bors rollup |
Wrapping now implements:
count_ones, count_zeros, leading_zeros,
trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be,
from_le, to_be, to_le, and pow
where T is:
u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize.
Docs were written for all these methods, as well as examples. The
examples mirror the ones on u8, u16, etc... for consistency.
Closes #32463